package com.example.tests;

import static org.junit.Assert.*;
import org.junit.*;

import com.example.model.SortedListOf;
import com.example.model.User;
import com.example.pages.UsersPage;

public class CreateUserTest extends TestBase{
  
  @Test
  public void testCreateNewUser(){
    UsersPage usersPage = goToMainPage()
    	.loginWithValidCredentials("admin", "admin")
    	.gotoUserManagement();
    	
    SortedListOf<User>	oldUserList = usersPage.getUsers();
    User user = new User()
    	.withName("user").withEmail("user@test.com").withPassword("test");
    if (oldUserList.contains(user)){
    	usersPage.deleteUser(user);
    	oldUserList = usersPage.getUsers();
    }
    usersPage.createUser(user);
    SortedListOf<User>	newUserList = usersPage.getUsers();
    
    assertEquals("User was not added",oldUserList.withAdded(user), newUserList);
  }
  

  
}
